package com.huli.Scheduled;


import com.huli.feign.IncomeClient;
import com.huli.feign.OwnerFeign;
import com.huli.feign.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class Scheduler {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Autowired
    IncomeClient incomeClient;

    @Autowired
    UserClient userClient;

    @Autowired
    OwnerFeign ownerFeign;

    //每隔2秒执行一次 暂时关闭
    @Scheduled(fixedRate = 2000)
    public void testTasks() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
        System.out.println(userClient.getUser(1));
    }

    //每天0：00执行 秒 分 时
//    @Scheduled(cron = "0 00 00 ? * *")
    public void testTasks2() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
        System.out.println("任务1 生成各角色日收入表");

        System.out.println("任务2 更新会员状态");
        ownerFeign.deleteOwnerVip();
        userClient.changeUserVip();
        System.out.println("任务3 冻结信誉不足的用户");
        userClient.changeStatus();
    }

}